import http from "client/utils/http";

export async function downloadFile(type, file, name) {
    name = name || file;
    let iframe = document.createElement("iframe");
    if (type == "temp" || type == "template") {
        iframe.src = `/api/v1/file/${type}/${file}?token=${localStorage.getItem("clienttoken")}&name=${name}`;
    } else {
        iframe.src = await http.get(`/api/v1/file/${type}/${file}?token=${localStorage.getItem("clienttoken")}`);
    }
    iframe.style.display = "none";
    document.body.appendChild(iframe);
}

export async function download(url) {
    let iframe = document.createElement("iframe");
    iframe.src = url;
    iframe.style.display = "none";
    document.body.appendChild(iframe);
}
